import Paging from '../../../wxjs/Paging.js'
import navToNext from '../../../wxjs/navToNext.js'
const app = getApp();

var pag = new Paging();

var data = {
  xhx_images: app.xhx_images,
  xhx_route: app.xhx_route,
};

var currentPage = {
  data,
  reqUrl: app.serAddrs.collList,
  onLoad,
  changeColl,
};

var page = Object.assign({}, pag.func(), navToNext, currentPage);

Page(page);

function onLoad() {
  const that = this;
  // 初始化
  that.pageListInit();
}

function changeColl(event) {
  const that = this;
  let index = event.currentTarget.dataset.index || 0;
  let lists = that.data.lists || [];

  app.middleware.requestAjax({
    serAddr: app.serAddrs.delColl,
    data: {
      goodsUuid: lists[index].goodsUuid
    },
    cancelToast: true,
    success: function(res) {
      lists.splice(index, 1);
      that.setData({
        lists
      })
    },
    fail: function(res) {
      app.middleware.showToast(res && res.msg || "请求失败");
    }
  })
}